#define _CRT_SECURE_NO_WARNINGS
#include "SList.h"



void STLPrint(SLTNode* phead)
{
	SLTNode* pcur = phead;
	while (pcur->next)
	{
		printf("%d->", pcur->data);
		pcur = pcur->next;
	}
	printf("NULL\n");
}

SLTNode* SLTBuyNode(SLDataType x)
{
	SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));
	if (newnode == NULL)
	{
		printf("malloc");
		exit(1);
	}
	newnode->data = x;
	newnode->next = NULL;
}
void SLTPushBack(SLTNode** pphead, SLDataType x)
{
	assert(*pphead);
	SLTNode* newnode = SLTBuyNode(x);
	if (*pphead ==NULL)
	{
		*pphead = newnode;
	}
	else
	{
		SLTNode* ptail = *pphead;
		while (ptail)
		{
			ptail = ptail->next;
		}
		ptail->next = newnode;
	}
}

void SLTPushFont(SLTNode** pphead, SLDataType x)
{
	assert(*pphead);
	SLTNode* newnode = SLTBuyNode(x);
	newnode->next = *pphead;
	*pphead = newnode;
}

void SLTPopBack(SLTNode** pphead)
{
	assert(pphead && *pphead);
	if ((*pphead)->next = NULL)
	{
		free(*pphead);
		*pphead = NULL;
	}
	SLTNode* prev = *pphead;
	SLTNode* ptail = *pphead;
	while (ptail->next)
	{
		prev = ptail;
		ptail = ptail->next;
	}
	free(ptail);
	ptail = NULL;
	prev->next = NULL;

}


